package com.cn.boot.student.controller.rbac;
import com.cn.boot.student.util.CommonResult;
import com.cn.boot.student.entity.PermissionEntity;
import com.cn.boot.student.service.rbac.IPermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 权限控制层
 */
@RestController
@Api(tags = "权限管理")
@RequestMapping("/admin/permission")
public class PermissionController {
    @Autowired
    private IPermissionService iPermissionService;
    /**
     * 查询所有
     */
    @PostMapping("/findAll")
    @PreAuthorize("hasAuthority('sys:permission:read')")
    @ApiOperation(value = "查询所有数据")
    public CommonResult findAll(PermissionEntity permissionEntity){
        return iPermissionService.findAll(permissionEntity);
    }

    /**
     * 查询所有
     */
    @PostMapping("/fuzzyQuery")
    @ResponseBody
    @PreAuthorize("hasAuthority('sys:permission:read')")
    @ApiOperation(value = "模糊查询")
    public CommonResult fuzzyQuery(PermissionEntity permissionEntity){
        return iPermissionService.fuzzyQuery(permissionEntity);
    }
    /**
     * 根据id查询权限信息
     */
    @PreAuthorize("hasAuthority('sys:permission:read')")
    @GetMapping("/findById")
    @ApiOperation(value = "根据id查询权限信息")
    public CommonResult findById(Integer id){
        return iPermissionService.findById(id);
    }
    /**
     * 添加数据
     */
    @PreAuthorize("hasAuthority('sys:permission:add')")
    @PostMapping("/add")
    @ApiOperation(value = "添加数据")
    public CommonResult add(PermissionEntity permissionEntity){
        return iPermissionService.add(permissionEntity);
    }

    /**
     * 更新数据
     */
    @PreAuthorize("hasAuthority('sys:permission:update')")
    @PostMapping("/update")
    @ApiOperation(value = "更新数据")
    public CommonResult update(PermissionEntity permissionEntity){
        return iPermissionService.update(permissionEntity);
    }
    /**
     * 删除数据
     */
    @PreAuthorize("hasAuthority('sys:permission:del')")
    @DeleteMapping("/del")
    @ApiOperation(value = "删除数据")
    public CommonResult del(Integer id){
        return iPermissionService.del(id);
    }

    /**
     * 批量删除
     */
    @PreAuthorize("hasAuthority('sys:permission:del')")
    @DeleteMapping("/dels")
    @ApiOperation(value = "批量删除")
    public CommonResult dels(List<Integer> ids){
        return iPermissionService.dels(ids);
    }
}
